package com.demo.jpa.service;

import com.demo.jpa.dao.repository.UserRepository;
import com.demo.jpa.exten.OnlyName;
import com.demo.jpa.exten.OnlyNameBySpel;
import com.demo.jpa.exten.OnlyNameBySimpleSpel;
import lombok.extern.log4j.Log4j2;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import javax.transaction.Transactional;

/**
 * @Author:LiaoYouLe
 * @Date: Created in 2018/7/25
 * @Description 返回结果扩展
 * @Modifyied By:
 */
@Log4j2
public class ResultExtention extends TestCase {
    @Autowired
    private UserRepository userRepository;

    @Test
    @Transactional
    public void onlyName() {
        userRepository.findByUidNotNull()
                .map(OnlyName::getUsername)
                .forEach(log::info);
    }

    @Test
    @Transactional
    public void onlyNameSpel1() {
        userRepository
                .queryByUidNotNull()
                .map(OnlyNameBySimpleSpel::getNameAge)
                .forEach(log::info);
    }


    @Test
    @Transactional
    public void onlyNameSpel2() {
        userRepository
                .findOneByUidNotNull()
                .map(OnlyNameBySpel::getNameAge)
                .forEach(log::info);
    }


    @Test
    @Transactional
    public void onlyNameSpel3() {
        userRepository
                .findTop3ByUidNotNull()
                .map(p->p.getNameAge("liaoyoule"))
                .forEach(log::info);
    }


}
